package com.fyw.magichome.ui;

import android.content.Context;
import android.os.Bundle;
import android.view.View;

import com.fyw.magichome.BaseActivity;
import com.fyw.magichome.Constants;
import com.fyw.magichome.R;
import com.fyw.magichome.bean.AccessToken;
import com.fyw.magichome.http.ClientService;
import com.fyw.magichome.http.RetrofitManager;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends BaseActivity {

    @Override
    public void initParam(Bundle param) {

    }

    @Override
    public View bindView() {
        return null;
    }

    @Override
    public int bindLayout() {
        return R.layout.activity_main;
    }

    @Override
    public void initView(View view) {
        Call<AccessToken> call = RetrofitManager.getInstance().createReq(ClientService.class)
                .getAccessToken("bab7a15562614aaf8b6dd669ce582442", "daee0e45592391dc003a4175696513c7");
        call.enqueue(new Callback<AccessToken>() {
            @Override
            public void onResponse(Call<AccessToken> call, Response<AccessToken> response) {
                if (response.body().getCode() == 200) {
                    Constants.accessTokenStr = response.body().getData().getAccessToken();
                    startActivity(CameraListActivity.class);
                    finish();
                } else
                    showToast(response.body().getMsg());
            }

            @Override
            public void onFailure(Call<AccessToken> call, Throwable throwable) {
                showToast(throwable.getMessage());
            }
        });
    }

    @Override
    public void doBusiness(Context mContext) {

    }

}
